package com.ruoyi.service.Impl;

import com.ruoyi.mapper.MemberMapper;
import com.ruoyi.model.LoginMember;
import com.ruoyi.model.Member;
import com.ruoyi.system.api.model.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @Author:Jiang
 * @Date: 2023/08/11/ 14:02
 **/
@Service
public class MemberDetailsServiceImpl implements UserDetailsService {
    @Autowired
    private MemberMapper memberMapper;
    @Override
    public  UserDetails loadUserByUsername(String tel) throws UsernameNotFoundException {
        Member member = memberMapper.selectMemberById(tel);
        if (member==null){
            throw new RuntimeException("用户名不存在");
        }

        //查询用户的权限信息
        List<String> permissions=new ArrayList<>(
                Arrays.asList("sys.user.add","order.manage.create")
        );

        LoginMember loginMember=new LoginMember(member,permissions);
        return loginMember;
    }
}
